<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Article;
use Illuminate\Http\Request;
use App\Models\Category;
use Illuminate\Support\Facades\Cache;
use Jenssegers\Agent\Agent as Agent;
class NewsController extends Controller
{
    
    public function index(Request $request)
    {
        //获取当前栏目
        $this->__cate_init__($request);
        $category = $this->category;
        
        if($request->catid == 25) {
            $where = ['post_status'=> 1, 'post_type'=>[26,27,28,29]];
        }else {
            $where = ['post_status' => 1,'post_type'=> $request->catid];
        }
        $pageList = Article::where($where)->orderBy('listorder', 'asc')->orderBy('id', 'desc')->paginate(15);
        $pageList->everypage = 15;
        $pageList->appends(['catid'=> $request->catid]);
        
        
        return view('news.index', compact('pageList', 'category'));
    }
    
    public function detail(Request $request)
    {
        
        $info = Article::findOrFail($request->id);
        $category = $info->Category;
        
        return view('news.detail', compact('info', 'category'));
    }
}


